# $Id: Logging.pm 36 2006-09-29 23:09:30Z cmauch $
# Author: Charles Mauch (cmauch@gmail.com)
# Description: Module to handle email logging
# Legal: (c) 2006 Charles Mauch, released under the terms of the GPLv2 or later

# -- [ sub: Logger ] --------------------------------------------------------
#
#Summary:      Subroutine to create a logfile of email traffic, in the future
#              it might make sense to store this in sql.
#Parameters:   (list|personal|spam|other), username, useremail, subject, folder, spamscore
#Return:       none

sub Logger {
    use MLDBM::Sync;                     # this gets the default, SDBM_File
    use MLDBM qw( DB_File Storable );    # use Storable for serializing
    use Fcntl qw(:DEFAULT);              # import symbols O_CREAT & O_RDWR for use with DBMs

    my ( $date, $score, $type, $fromname, $fromemail, $subject, $folder ) = @_;

    my $sync = tie my %database, 'MLDBM::Sync', $MauchConfig::maildatabase, O_CREAT | O_RDWR, 0640
      or die "Cannot open $MauchConfig::maildatabase $!\n";
    $sync->Lock;
    my $record = $database{ $date };
    $record->{ 'date' }    = $date;
    $record->{ 'score' }   = $score;
    $record->{ 'type' }    = $type;
    $record->{ 'from' }    = $fromname;
    $record->{ 'email' }   = $fromemail;
    $record->{ 'subject' } = $subject;
    $record->{ 'folder' }  = $folder;
    $database{ $date }     = $record;
    $sync->UnLock;
    untie %database;
} ## end sub Logger
1;
